package src.edu.wayne.cs.csc4110.hw6.plugins;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import src.edu.wayne.cs.csc4110.hw6.interfaces.PluginToFrameWorkInterface;

public class ExamplePluginOne extends GamePlugin {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4849298563286405189L;

	ExamplePluginOne(PluginToFrameWorkInterface frameWork){
		
		super(frameWork);
		setGameName(this.toString());
	}

	@Override
	public void startGame() {
		setPlayerList(null);
		setCurrentUser(getNextPlayer());
		showForm();
	}
	
	private void showForm(){
		JPanel myPanel = new JPanel();
		myPanel.add(new JButton(getCurrentUser().getFullname()));
		myPanel.add(getNextPlayerButton());
		myPanel.add(getDoNothingButton());
		myPanel.add(getQuitButton());

		frameWork.setCurrentPanel(myPanel, this.getGameName());
	}
	
	private JButton getDoNothingButton(){
		JButton jbtnSubmitLogin = new JButton("Push this to see a message");
		jbtnSubmitLogin.addActionListener(
    			new ActionListener() 
    			{
    				public void actionPerformed(ActionEvent e)
    				{
    					JOptionPane.showMessageDialog(null, "This should do something, but this is just a little example");
    				}
    			}
    		);  
		
		return jbtnSubmitLogin;

	}
	
	private JButton getNextPlayerButton(){
		JButton jbtnSubmitLogin = new JButton("Done");
		jbtnSubmitLogin.addActionListener(
    			new ActionListener() 
    			{
    				public void actionPerformed(ActionEvent e)
    				{
    					startNextTurn();
    				}
    			}
    		);  
		
		return jbtnSubmitLogin;

	}

	private JButton getQuitButton(){
		JButton jbtnSubmitLogin = new JButton("Quit");
		jbtnSubmitLogin.addActionListener(
    			new ActionListener() 
    			{
    				public void actionPerformed(ActionEvent e)
    				{
    					endGame();
    				}
    			}
    		);  
		
		return jbtnSubmitLogin;
	}
	
	private void startNextTurn(){
		setCurrentUser(getNextPlayer());
		showForm();
	}
}